<template>
	<view class="login form">
		<view class="ipt-group">
			<image class="icon" src="../../static/images/ac1.png" mode="aspectFit"></image>
			<input class="ipt" type="text" value="" placeholder="请输入账号" placeholder-class="ipt-pc" v-model="form.account">
		</view>
		<view class="ipt-group">
			<image class="icon" src="../../static/images/ac2.png" mode="aspectFit"></image>
			<input class="ipt" type="password" value="" placeholder="请输入密码" placeholder-class="ipt-pc" v-model="form.password">
		</view>
		<!-- <view class="ipt-group">
			<image class="icon" src="../../static/images/ac4.png" mode="aspectFit"></image>
			<input class="ipt" type="text" value="" placeholder="请输入验证码" placeholder-class="ipt-pc">
		</view> -->
		
		<view class="btn-wrap">
			<button class="cu-btn block radius login" @click="login">
				登录
			</button>
		</view>
	</view>
</template>

<script>
	import store from '@/store.js'
	export default {
		data() {
			return {
				form: {
					account: '',
					password: ''
				}
			};
		},
		methods: {
			login() {
				if (this.form.account && this.form.password) {
					this.$u.post('/passport/login', this.form).then(res => {
						console.log(res)
						if (res.data.code == 0) {
							let token = res.data.result.token
							this.$store.commit('setToken', token)
							
							this.getUserInfo();
						} else if (res.data.code == -2) {
							uni.navigateTo({
								url: '/pages/account/step1?token=' + res.data.result.token
							})
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
					})
				}
				
			},
			getUserInfo() {
				this.$u.get('member/info').then(res => {
					let userinfo = res.data.result.userinfo
					this.$store.commit('userLogin', userinfo)
					uni.switchTab({
					    url: '/pages/mine/mine'
					})
				})
			},
		}
	}
</script>

<style lang="scss">
	
</style>
